<%@	page import ="java.util.ArrayList" %>
<%@	page import ="java.util.Iterator" %>
<%@	page import ="java.util.List" %>
<%@	page import ="com.adisi.objetos.Auto" %>
<%@	page import ="com.adisi.objetos.Chofer" %>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<jsp:directive.include file="headerComun.jsp" />
<body>	
<script type="text/javascript">

	$(window).load(function(){
		$('#formulario').validate({
			rules:{
	        	id_chofer: {
	        		required:true,
	        		min:1
	        	},
	        	id_auto:{
	        		required:true,
	        		min:1
	        	},
	        	kms_auto:{
	        		digits: true,
	        		required: true,
	        		min: {
		        		depends: function(element) {
		        	          return ($("#kms_auto").val()*1>=$('#id_auto option:selected').attr('data')*1);
		        	        }
	        		}
	        	}
				
			},
			messages: {
				id_chofer:'Se debe elegir un chofer.',
				id_auto: 'Se debe elegir un auto.',
				kms_auto: {
					min: 'El kilometraje debe ser superior al ya cargado.',	
				}
				
			},
	        highlight: function(element) {
	            $(element).closest('.form-group').addClass('has-error');
	        },
	        unhighlight: function(element) {
	            $(element).closest('.form-group').removeClass('has-error');
	        },
	        errorElement: 'span',
	        errorClass: 'help-block',
	        errorPlacement: function(error, element) {
		            if(element.parent('.input-group').length) {
		                error.insertAfter(element.parent());
		            } else {
		                error.insertAfter(element);
		            }
		        }		
		});

		
		$('#id_auto').change(function(){
			$('#kms_auto').val($('#id_auto option:selected').attr('data'));
		});
		
	}); 
</script>	
	
<div class="container">
	<jsp:directive.include file="menuNavegacion.jsp" />
	<div class="row clearfix">
		<div class="col-md-4 column col-md-offset-3">
			<h3>Alta de Jornada </h3>
		</div>
	</div>
	<div class="row clearfix">
		<div class="col-md-6 column col-md-offset-3">
			<%
				ArrayList<Auto> autos = (ArrayList<Auto>)request.getAttribute("autos");
				ArrayList<Chofer> choferes = (ArrayList<Chofer>)request.getAttribute("choferes");
			
			%>	
			<form role="form" action="jornada" method="post" name="formulario" id="formulario">
				<div class="form-group" style="display:hidden">
					<input type="hidden" id="jornada_accion" name="jornada_accion" value="agregar">
				</div>
				<div class="form-group">
					<label for="turno">Turno</label>
					<select name="turno"  id="turno" class="form-control">
						<option value="DIA">DIA</option>
						<option value="NOCHE">NOCHE</option>
					</select>					
									
				</div>
							
				<div class="form-group">
					<label for="id_chofer">Chofer</label>
					<select name="id_chofer"  id="id_chofer" class="form-control">
						<option value=0>Seleccione el chofer</option>
						<%
							for(int i = 0; i < choferes.size(); i++) {
						%>
								<option value="<%= choferes.get(i).getIdChofer() %>" ><%= choferes.get(i).getApellido()%></option>
						<% } %>
					</select>					
									
				</div>
				<div class="form-group">
					<label for="id_auto">Auto</label>
					<select name="id_auto"  id="id_auto" class="form-control">
						<option value=0 data="">Seleccione el auto</option>
						<%
							for(int i = 0; i < autos.size(); i++) {
						%>
								<option value="<%= autos.get(i).getIdAuto() %>" data="<%= autos.get(i).getKms().toString() %>"><%= autos.get(i).getMarcaAuto()%> <%= autos.get(i).getDominioAuto()%></option>
						<% } %>
					</select>					
				</div>
				<div class="form-group">
					<label for="kms_auto">Kilometraje del auto</label>
					<input type="text" name="kms_auto"  id="kms_auto" class="form-control" />
				</div>				
				<button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-floppy-save"></span> Grabar</button>
				<a  href="jornada?lst" type="cancel" class="btn btn-warning"><span class=" glyphicon glyphicon-ban-circle"></span> Cancelar</a>
				
			</form>

					

		</div>
	</div>
</div>

</body>
</html>